Page({
  data: {
    kind: '2',
    current: "",
    groups: [],
    members: [],
    warning: []
  },

  toPerson: function(e) {
    var group_idx = e.currentTarget.dataset.group_idx
    var member_idx = e.currentTarget.dataset.member_idx

    wx.navigateTo({
      url: '../exam_person/exam_person?studentId=' + this.data.members[group_idx][member_idx][0] + "&name=" + this.data.members[group_idx][member_idx][1] + "&hint=" + this.data.warning[group_idx][member_idx].category2,
    })
  },


  onShow: function() {

  },

  onLoad: function(options) {
    var that = this;

    this.setData({
      kind: getApp().globalData.kind,
      current: options.current
    })

    //获取当前班级
    wx.request({
      url: getApp().globalData.my_server + "/mark/get_current_class",
      data: {
        current: this.data.current,
        exam_id: getApp().globalData.exam._id
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        console.log(res)
        if (res.data.error_no == 2) {
          wx.showModal({
            title: '哎呀～',
            content: res.data.error_msg,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else if (res.data.error_no == 0) {
          var groups = res.data.groups
          var members_temp = []

          for (var i = 0; i < groups.length; i++) {
            var group_members = groups[i].members.split("/").map((member) => {
              return member.split(":")
            })
            members_temp.push(group_members)
          }

          that.setData({
            groups: groups,
            members: members_temp
          })

          var warningRaw = getApp().globalData.warning
          var warningID = warningRaw.map((person) => {
            return person.stu_number
          })
          var warning = []
          for (var m = 0; m < members_temp.length; m++) {
            warning.push([])
            for (var k = 0; k < members_temp[m].length; k++) {
              
              if (warningID.includes(members_temp[m][k][0])){
                var person = warningRaw[warningID.indexOf(members_temp[m][k][0])]
                if (person.category1 == "重度预警"){
                  person.category1 = 2
                } else if (person.category1 == "轻度预警"){
                  person.category1 = 1
                }
                warning[m].push(person)
              }else{
                warning[m].push(0)
              }
            }
          }
          that.setData({
            warning: warning
          })
        }
      },
      fail: function(res) {
        wx.showModal({
          title: '哎呀～',
          content: '获取当前班级失败',
          success: function(res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
        console.log("fail!", res)
      },
      complete: function(res) {

      }
    })

  },


})